/**
 * fileName:  ArgumentCostReader.java
 * author:  Pitaya
 * Company:  Cloudland Studio
 * Createdate:  2014-6-7 下午02:55:27
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-7            Pitaya            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.read;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseReader;
import org.cloudland.commercial.masterdata.store.entity.CostEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.ArgumentCostEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.ArgumentCostMapper;
import org.springframework.stereotype.Service;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  ArgumentCostReader
 * @author  Pitaya
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Service
public class ArgumentCostReader implements DatabaseReader<CostEntity>{
	
	@Resource(name = "argumentCostMapper")
	private ArgumentCostMapper costMapper;

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *   
	 */
	public ArgumentCostReader() {
	}
	
	/**
	 * <pre>
	 * 查询根节点
	 * </pre>
	 *
	 * @return   
	 */
	public List<CostEntity> findArgumentCostRoot() {
		return findChildCostById("");
	}
	
	/**
	 * <pre>
	 * 根据参数值编号获取参数值
	 * </pre>
	 *
	 * @param costId
	 * @return   
	 */
	public CostEntity findCostById(String costId)
	{
		ArgumentCostEntity daoCostEntity = costMapper.getById(costId);
		
		CostEntity costEntity = null;
		if(null != daoCostEntity)
		{
			costEntity = new CostEntity(daoCostEntity.getId(), daoCostEntity.getName(), daoCostEntity.getParentId());
		}
		return costEntity;
	}
	
	/**
	 * <pre>
	 * 根据参数值查询子参数值
	 * </pre>
	 *
	 * @param costId
	 * @return   
	 */
	public List<CostEntity> findChildCostById(String costId)
	{
		List<ArgumentCostEntity> entityList = costMapper.getByParentId(costId);
		
		if(null == entityList || entityList.size() <= 0)
		{
			return null;
		}
		
		List<CostEntity> costList = new ArrayList<CostEntity>(entityList.size());
		for(ArgumentCostEntity daoEntity : entityList)
		{
			costList.add(new CostEntity(daoEntity.getId(),daoEntity.getName(),daoEntity.getParentId()));
		}
		return costList;
	}
}
